package com.example.rss_reder;

import java.util.ArrayList;

import android.app.Service;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SubAdapter extends BaseAdapter{

	Context context;
	ArrayList<WeatherList> list;
	LayoutInflater inflater;
	int w1,w2;
	
	SubAdapter(Context c, ArrayList<WeatherList> l){
		this.context = c;
		this.list = l;
		Display display = ((WindowManager)
				c.getSystemService(Service.WINDOW_SERVICE)).getDefaultDisplay();
			float windowWidth = display.getWidth();
		
			w1 = (int)(windowWidth/5);
			w2 = (int)(windowWidth/5*4/3);
			
		inflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0).getTime();
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		if(arg1 == null){
			arg1 = inflater.inflate(R.layout.list_sub, arg2, false);
		}

			
		TextView t = (TextView)arg1.findViewById(R.id.tv_rain);
		t.setText(list.get(arg0).getRain());
		t.setWidth(w2);
		TextView t1 = (TextView)arg1.findViewById(R.id.tv_temp);
		t1.setWidth(w2);
		t1.setText(list.get(arg0).getTemp());
		TextView t2 = (TextView)arg1.findViewById(R.id.tv_time);
		t2.setWidth(w1);
		t2.setText(list.get(arg0).getTime());
		t2.setTextColor(Color.WHITE);
		TextView t3 = (TextView)arg1.findViewById(R.id.tv_weather);
		t3.setWidth(w2);
		t3.setText(list.get(arg0).getWeather());
		
		return arg1;
	}

}
